package com.heima.kafka.producer;

import com.alibaba.fastjson.JSON;
import com.heima.kafka.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ybw
 * @version 1.0
 * @date 2021/12/18 16:26
 */
@RestController
public class ProducerBoot {
  @Autowired private KafkaTemplate<String, String> kafkaTemplate;

  @GetMapping("/send")
  public String send() {
    kafkaTemplate.send("boot-01", "测试测试11111");
    return "发送成功";
  }

  @GetMapping("/send2")
  public String send2() {
    User user = new User();
    user.setAge(12);
    user.setName("zhangsan");
    String s = JSON.toJSONString(user);
    kafkaTemplate.send("boot-02", s);
    return "发送成功";
  }
}
